/*
 *  Copyright 2010 INFN - APE group
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#pragma once

namespace cuqu
{
    enum ret_values {
        SUCCESS    = 0,
        WOULDBLOCK = -1,
        INVALID    = -2,
        UNSET      = -10000,
    };

    static const int timeout_infinite = -1;

    namespace detail
    {
        typedef uint32_t word_t;

        enum {
            event_magic = 0xa5c4a5c4U
        };

        template <typename T>
        struct event
        {
            enum { nwords = (sizeof(T) + sizeof(word_t) - 1)/sizeof(word_t) };
            typedef struct { word_t w[nwords]; } array_t;
            union {
                array_t a;
                T t;
            } u;
        };

        // allocated as host pinned memory
        //template <typename T>
        struct raw_queue {
            // hot cache line
            uint32_t nr;
            uint32_t nw;
            uint32_t pad1;
            uint32_t pad2;

            // cold cache line
            //uint32_t nevents;
            //uint32_t mask;
            //uint32_t pad3;
            //uint32_t pad4;

            // events follow here
            //event_t events[0];
            uint32_t events[0];
            //event<T> events[0];
        };
        typedef struct raw_queue raw_queue_t;

    } // end namespace detail

    //typedef detail::cuda_queue_t cuda_queue_t;

} // end namespace cuqu

/*
 * Local variables:
 *  mode: c++
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 *  indent-tabs-mode: nil
 * End:
 */
